package com.xjzd.std.variance;

import java.util.ArrayList;
import java.util.List;

public class Covariance {

    private static class Animal {
        public void sound() {
            System.out.println("Animal sound");
        }
    }

    private static class Dog extends Animal {
        @Override
        public void sound() {
            System.out.println("Bark");
        }
    }

    private static void makeSound(List<? extends Animal> animals) {
        for (Animal animal : animals) {
            animal.sound(); // 可以调用 Animal 的方法
        }
    }

    public static void main(String[] args) {
        List<Dog> dogs = new ArrayList<>();
        dogs.add(new Dog());
        makeSound(dogs);
    }
}
